package cn.hospital.seviceimpl;

import cn.hospital.dao.*;
import cn.hospital.entity.*;
import cn.hospital.service.DropDownBoxQueryService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 查询下拉框数据展示
 */
@Service
public class DropDownBoxQueryServiceImpl implements DropDownBoxQueryService {
    @Resource
    private RoleMapper roleMapper;
    @Resource
    private HospitalMapper hospitalMapper;
    @Resource
    private DepartmentMapper departmentMapper;
    @Resource
    private GrouptableMapper grouptableMapper;
    @Resource
    private MeaningUserMapper meaningUserMapper;
    @Resource
    private NationalMapper nationalMapper;
    @Resource
    private AddressCityMapper addressCityMapper;
    @Resource
    private AddressCountyMapper addressCountyMapper;
    @Resource
    private AddressProvinceMapper addressProvinceMapper;
    @Resource
    private WardRoomMapper wardRoomMapper;
    @Resource
    private WardBedMapper wardBedMapper;
    @Resource
    private WardLayerMapper wardLayerMapper;
    @Resource
    private WardBuildingMapper wardBuildingMapper;

    /**
     * 查询职位信息
     * @return
     */
    public List<Role> findRole() {
        return roleMapper.findRole();
    }


    /**
     * 查询医院信息
     * @return
     */
    public List<Hospital> findHospital() {
        return hospitalMapper.findHospital();
    }

    /**
     * 查询科室信息
     * @return
     */
    public List<Department> findDeparment() {
        return departmentMapper.findDeparment();
    }

    /**
     * 根据科室ID查询科室所属的医院id
     * @param departmentId 科室id
     * @return
     */
    public Department findByDepartmentId(String departmentId) {
        return departmentMapper.findByDepartmentId(departmentId);
    }

    /**
     * 根据医院id查询医院下的科室
     * @param session 从session中获取登录人所属的科室
     * @return
     */
    public List<Department> findByhospitalId(HttpSession session) {
        MeaningUser meaningUser = (MeaningUser) session.getAttribute("meaningUser");
        String departmentId = String.valueOf(meaningUser.getDepartmentId());
        Department department = findByDepartmentId(departmentId);
        String hospitalId = String.valueOf(department.getHospitalId());
        return departmentMapper.findByhospitalId(hospitalId);
    }

    /**
     * 查询随访组信息
     * @return
     */
    public List<Grouptable> findByGrouptable() {
        return grouptableMapper.findBy();
    }

    /**
     * 查询所有医生信息（医生id，医生姓名）
     *
     * @return
     */
    public List<MeaningUser> selectByMeaningUser() {
        return meaningUserMapper.selectBy();
    }

    /**
     * 查询民族
     * @return
     */
    @Override
    public List<National> findNational() {
        return nationalMapper.findNational();
    }

    /**
     * 查询省市县
     * @return
     */
    @Override
    public Map<String, Object> findAddress() {
        Map<String, Object> map = new HashMap<>();
        map.put("cityList", addressCityMapper.findCity());
        map.put("provinceList", addressProvinceMapper.findProvince());
        map.put("countyList", addressCountyMapper.findCounty());
        return map;
    }

    /**
     * 查询病区、楼层、房间、床位
     * @return
     */
    @Override
    public Map<String, Object> findWard() {
        Map<String, Object> map = new HashMap<>();
        map.put("roomList", wardRoomMapper.findRoom());
        map.put("bedList", wardBedMapper.findBed());
        map.put("layerList", wardLayerMapper.findLayer());
        map.put("buildingList", wardBuildingMapper.findBuilding());
        return map;
    }
}
